<?php
session_start();
include_once 'core/function.general.php';
checkIfLoggedIn();
include_once 'core/function.banner.php';
include_once 'core/function.mainmenu.php';
include_once 'core/function.customer.php';
$customer = new customerManager();
include_once 'core/function.leads.php';
$leads = new leadsManager();
include_once 'core/function.rest.php';
include_once 'core/dbconnect.php';
$sql = new ownedsql;
$rest = new restManager();

if (isset($_GET['mode'])) {
    $mode = $_GET['mode'];
} else {
    $mode = "";
}

switch ($mode) {
    case "":
        $sql->connect();
        $noMode = true;

        //autocomple CID
        $cid = "SELECT cid FROM 3i_customers ORDER BY cid ASC";
        $sql->query($cid);
        $cid = $sql->query;
        $cidCount = mysql_num_rows($cid);
        $i = 1;
        $cidVal = "";
        while ($itemCid = mysql_fetch_array($cid)) {
            if ($cidCount == $i) {
                $end = "";
            } else {
                $end = ",";
            }
            $cidVal .= "\"" . $itemCid['cid'] . "\"" . $end;
            $i++;
        }

        //autocomplete User Name
        $cname = "SELECT DISTINCT cSname, cFname FROM 3i_customers ORDER BY cid ASC";
        $sql->query($cname);
        $cname = $sql->query;
        $cnameCount = mysql_num_rows($cname);
        $i = 1;
        $cnameVal = "";
        while ($itemcName = mysql_fetch_array($cname)) {
            if ($cnameCount == $i) {
                $end = "";
            } else {
                $end = ",";
            }
            $cnameVal .= "\"" . $itemcName['cSname'] . ", " . $itemcName['cFname'] . "\"" .
                $end;
            $i++;
        }

        //autocomplete email
        $email = "SELECT DISTINCT cemail FROM 3i_customers ORDER BY cid ASC";
        $sql->query($email);
        $email = $sql->query;
        $emailCount = mysql_num_rows($email);
        $i = 1;
        $emailVal = "";
        while ($itemcName = mysql_fetch_array($email)) {
            if ($emailCount == $i) {
                $end = "";
            } else {
                $end = ",";
            }
            $emailVal .= "\"" . $itemcName['cemail'] . "\"" . $end;
            $i++;
        }

        //autocomplete phone
        $phone = "SELECT DISTINCT cphone FROM 3i_customers ORDER BY cid ASC";
        $sql->query($phone);
        $phone = $sql->query;
        $phoneCount = mysql_num_rows($phone);
        $i = 1;
        $phoneVal = "";
        while ($itemcName = mysql_fetch_array($phone)) {
            if ($phoneCount == $i) {
                $end = "";
            } else {
                $end = ",";
            }
            $phoneVal .= "\"" . $itemcName['cphone'] . "\"" . $end;
            $i++;
        }

        $sql->kill();
        break;
    default:
    $noMode = false;
        break;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="hu" lang="hu">

<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="author" content="Galicz Miklós" />
    <meta name="copyright" content="Copyright 2011" />
    <meta name="Designer" content="Galicz Miklós" />
    <meta name="title" content="Ideális Ingatlan Iroda Kft." />
    <link rel="stylesheet" type="text/css" href="css/reset.css" />
    <link rel="stylesheet" type="text/css" href="css/general.css" />
    <link rel="stylesheet" type="text/css" href="css/leads.css" />
    <link rel="stylesheet" type="text/css" href="libs/jq-ui/jquery.ui.all.css" />
    <link rel="shortcut icon" type="image/x-icon" href="imgs/favicon.ico" />
    <script type="text/javascript" src="libs/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="libs/jquery-ui-1.8.14.custom.min.js"></script>
    <?php
switch ($mode) {
    case "restimg":
?>
    <link href="/libs/upload/uploadify.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="/libs/upload/swfobject.js"></script>
    <script type="text/javascript" src="/libs/upload/jquery.uploadify.v2.1.4.min.js"></script>
    <script type="text/javascript">
				$(function() {
				$('#file_upload').uploadify({
  'uploader'  : '/libs/upload/uploadify.swf',
        'script'    : '/core/function.upload.rest.php',
        'cancelImg' : '/libs/upload/cancel.png',
        'folder'    : '/images/rest/<?php echo $_GET['rid'] ?>',
  'multi'          : false,
  'auto'           : true,
  'fileExt'        : '*.jpg;*.gif;*.png',
  'fileDesc'       : 'Képek (.JPG, .GIF, .PNG)',
  'queueID'        : 'custom-queue',
  'queueSizeLimit' : 3,
  'simUploadLimit' : 1,
  'scriptData'     : {'rid':<?php echo $_GET['rid'] ?>},
  'removeCompleted': false,
  'onSelectOnce'   : function(event,data) {
      $('#status-message').text(data.filesSelected + ' fájl lett hozzáadva a sorhoz.');
    },
  'onAllComplete'  : function(event,data) {
      $('#status-message').text(data.filesUploaded + ' fájl feltöltve, ' + data.errors + ' hiba.');
    }
});				});
				</script>

            <?php
        break;
    default:
        break;
}
?>
	<title>IRA-MS/Ügyletek</title>
    <?php
if ($noMode == true) {
?>
    <script type="text/javascript">
    $(document).ready(function() {
        $("input#cid").autocomplete({
            source: [<?php echo $cidVal; ?>]
        });
        $("input#name").autocomplete({
            source: [<?php echo $cnameVal; ?>]
        });
        $("input#email").autocomplete({
            source: [<?php echo $emailVal; ?>]
        });
        $("input#phone").autocomplete({
            source: [<?php echo $phoneVal; ?>]
        });
    });
    </script>
      <?php
} 
?>
 </head>
 <body>
 <div id="wrapper">
    <?php
banner();
?>
   <div id="leftCol">
    <?php
mainMenu();
?>
 </div>
 <div id="rightCol">
    <?php

switch ($mode) {
    case "newcustomer":
        if (!isset($_POST['submitCustomer'])) {
            $customer->newCustomerForm();
        } else {
            $customer->newCustomerFormAction();
        }
        break;
    case "editcustomer":
        if (!isset($_POST['submitEditCustomer'])) {
            $customer->editCustomerForm($_GET['cid']);
        } else {
            $customer->editCustomerFormAction();
        }
        break;
    case "viewcustomer":
        $leads->viewCustomer($_GET['cid']);
        break;
    case "deletecustomer":
        $customer->deleteCustomer($_GET['cid']);
        break;
    case "activatecustomer":
        $customer->activateCustomer($_GET['cid']);
        break;
    case "listcustomers":
        $customer->listCustomers();
        break;
    case "newrest":
        if (!isset($_POST['preSelect'])) {
            if (isset($_POST['submitFlat'])) {
                $rest->newFlatFormAction();
            } else {
             $rest->selectRESTTypeForm($_GET['uid'],$_GET['cid']);   
            }
        } else {
            $rest->selectRESTTypeFormAction();
        }
        
        break;
    case "viewrest":
        $rest->RestActionMenu($_GET['rid']);
        break;
    case "restimg":
?>
        <div class="box">
        <div id="status-message">Select some files to upload:</div>
<input id="file_upload" type="file" name="Filedata" />
<div id="custom-queue"></div>
</div>
        <?php
        break;
    default:
        if (isset($_POST['cSearch'])) {
            $leads->customerSearchAction();
        } elseif (isset($_POST['restSearch'])) {
            echo "ingatlan keresés";
        } else {
?>
    <table id="overSearch">
        <tr>
            <td>
            <form action="" method="post">
            <fieldset id="cSearch">
                <legend>Ügyfél keresés</legend>
                <table>
                    <tr>
                        <td id="leftLabel">cid#:</td>
                        <td><input type="text" name="cid" id="cid" /></td>
                    </tr>
                    <tr>
                        <td id="leftLabel">Név:</td>
                        <td><input type="text" name="name" id="name" /></td>
                    </tr>
                    <tr>
                        <td id="leftLabel">email:</td>
                        <td><input type="text" name="email" id="email" /></td>
                    </tr>
                    <tr>
                        <td id="leftLabel">tel.:</td>
                        <td><input type="text" name="phone" id="phone" /></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="cSearch" /></td>
                    </tr>
                </table>
            </fieldset>
            </form>
            </td>
            <td>
            <form action="" method="post">
            <fieldset id="restSearch">
                <legend>Ingatlan keresés</legend>
                <table>
                    <tr>
                        <td>rid#:</td>
                        <td><input type="text" name="rid" /></td>
                    </tr>
                    <tr>
                        <td>Méret:</td>
                        <td><input type="text" name="size1" size="3" /> - <input type="text" name="size2" size="3" /> m<sup>2</sup></td>
                    </tr>
                    <tr>
                        <td>ár:</td>
                        <td><input type="text" name="price1" />-<input type="text" name="price2" /> Ft között</td>
                    </tr>
                    <tr>
                        <td>Város:</td>
                        <td>
                            <select>
                                <option value="1">Budapest</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Kerület:</td>
                        <td><input type="checkbox" /> x Sok</td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="restSearch" /></td>
                    </tr>
                </table>
            </fieldset>
            </form>
            </td>
        </tr>
    </table>
    <?php
            break;
        }
}

?>
</div>
 </div>
 </body>
 </html>